package cn.hbwe.controller;


import cn.hbwe.pojo.entity.Department;
import cn.hbwe.service.IDepartmentService;
import cn.hbwe.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 7组
 * @since 2023-10-18
 */
@RestController
@RequestMapping("/department")
@Api(tags = "科室类接口")
@CrossOrigin
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;

    /**
     * 查询全部科室
     * @return
     */
    @GetMapping("/getAll")
    @ApiOperation("查询全部科室")
    public Result<List<Department>> getAll() {
        List<Department> list = departmentService.list();
        return Result.success(list);
    }

    /**
     * 根据id查询科室信息
     * @param id
     * @return
     */
    @ApiOperation("根据id查询科室信息")
    @GetMapping("/{id}")
    public Result<Department> getById(@PathVariable Integer id) {
        Department department = departmentService.getById(id);
        return Result.success(department);
    }

    /**
     * 添加科室
     * @param department
     * @return
     */
    @ApiOperation("添加科室")
    @PostMapping("/save")
    public Result<String> saveDepartment(@RequestBody Department department) {
        departmentService.save(department);
        return Result.success("添加科室成功");
    }

    /**
     * 修改科室信息
     * @param department
     * @return
     */
    @ApiOperation("修改科室信息")
    @PutMapping("/modify")
    public Result<String> modifyDepartment(@RequestBody Department department) {
        departmentService.updateById(department);
        return Result.success("科室信息修改成功");
    }

    /**
     * 根据id删除科室
     * @param id
     * @return
     */
    @ApiOperation("根据id删除科室")
    @DeleteMapping("/remove/{id}")
    public Result<String> removeDepartment(@PathVariable Integer id) {
        departmentService.removeDepartment(id);
        return Result.success("科室删除成功");
    }
}
